
<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>传智教育</span>
        <el-dropdown style="float: right; padding: 3px 3px">
          <span class="el-dropdown-link">操作</span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>添加子部门</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <el-button style="float: right; padding: 3px 3px" type="text">负责人</el-button>
      </div>
      <el-tree :data="data" :props="defaultProps">
        <span class="custom-tree-node" slot-scope="{ node,data }">
          <span>{{ node.label }}</span>
          <span>
            <el-button type="text" size="mini">{{data.manager}}</el-button>
            <el-dropdown>
              <span class="el-dropdown-link">操作</span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>添加子部门</el-dropdown-item>
                <el-dropdown-item>编辑部门</el-dropdown-item>
                <el-dropdown-item>删除部门</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </span>
        </span>
      </el-tree>
    </el-card>
  </div>
</template>

<script>
import { department } from '@/api/commpany'
import { handlerData } from '@/utils/handlerData'
export default {
  name: 'DepartmentsView',
  components: {},
  props: {},
  data () {
    return {
      data: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      }
    }
  },
  computed: {},
  watch: {},
  created () {
    this.getdepartmentFn()
  },
  mounted () {},
  methods: {
    async  getdepartmentFn () {
      const { data: { depts } } = await department()
      console.log(depts)
      // 数据的处理，形成树状结构
      this.data = handlerData(depts)
    }
  }
}
</script>

<style lang="less" scoped>
.box-card {
  padding: 20px 140px;
  ::v-deep .el-card__header {
    border: none;
  }
  ::v-deep .custom-tree-node {
    display: flex;
    flex: 1;
    justify-content: space-between;
  }
}
</style>
